﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CourseSystem.Core.Entities;
using CourseSystem.Core.SqlServerDAL;

namespace CourseSystem.Core.BLL
{
    public class ChapterBLL
    {
        public static IQueryable<ChapterInfo> GetList()
        {
            using (var dal = new ChapterDAL(Settings.ConnectionName))
            {
                var re = dal.SelectQueryable(o => true);
                return re;
            }
        }

        public static byte GetMax()
        {
            using (var dal = new ChapterDAL(Settings.ConnectionName))
            {
                var list = dal.Select(o => true);
                if (list.Count < 1)
                    return 0;
                return list.Max(o => o.OrderId);
            }
        }

        public static ChapterInfo Get(int id)
        {
            using (var dal = new ChapterDAL(Settings.ConnectionName))
            {
                var re = dal.SelectSingle(o => o.Id == id);
                return re;
            }
        }

        public static bool Del(int id)
        {
            using (var dal = new ChapterDAL(Settings.ConnectionName))
            {
                return dal.Delete(o => o.Id == id) != null;
            }
        }

        public static bool Edit(ChapterInfo info)
        {
            using (var dal = new ChapterDAL(Settings.ConnectionName))
            {
                return dal.Update(info) != null;
            }
        }

        public static bool Add(ChapterInfo info)
        {
            using (var dal = new ChapterDAL(Settings.ConnectionName))
            {
                return dal.Add(info) != null;
            }
        }

        public static bool Add(IEnumerable<ChapterInfo> list)
        {
            using (var dal = new ChapterDAL(Settings.ConnectionName))
            {
                return dal.Add(list) != null;
            }
        }
    }
}
